package com.plugin.src;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.*;

import java.util.*;

public class Metricas {

	// private int result;
	private List<String> listaImplementacoesList;
	private List<String> listaImplementacoesMap;
	private List<String> listaImplementacoesSet, listaMetodosUsamOrdem;
	private String nomeVariavelContains, argumentoIfContains;
	private HashMap<String, Integer[]> mapVariaveis;
	private HashMap<String, Integer> mapVariaveisSet;
	private HashSet<String> variaveisTemporarias;

	List<Integer> lista_posicao_chamadas_metodos_vector_synchronized;
	private final String[] IMPLEMENTACOES_LIST_ARRAY = { "ArrayList",
			"LinkedList", "Vector", "Stack", "CopyOnWriteArrayList" };
	private final String[] IMPLEMENTACOES_SET_ARRAY = { "HashSet", "TreeSet",
			"LinkedHashSet", "ConcurrentSkipListSet", "CopyOnWriteArraySet" };
	private final String[] INPLEMENTACOES_MAP_ARRAY = { "SortedMap",
			"NavigableMap", "ConcurrentMap", "ConcurrentNavigableMap",
			"HashMap", "Hashtable", "EnumMap", "WeakHashMap", "Properties",
			"IdentityHashMap", "ConcurrentHashMap", "LinkedHashMap",
			"ConcurrentSkipListMap", "TreeMap" };

	public Metricas() {
		this.listaImplementacoesList = Arrays.asList(IMPLEMENTACOES_LIST_ARRAY);
		this.listaImplementacoesMap = Arrays.asList(INPLEMENTACOES_MAP_ARRAY);
		this.listaImplementacoesSet = Arrays.asList(IMPLEMENTACOES_SET_ARRAY);
		listaMetodosUsamOrdem = new ArrayList<String>();
		povoaListaMetodosUsamOrdem();
	}

	public HashMap<String, Map<String, Integer[]>> containsAntesDeAddList(
			IPackageFragment mypackage) throws JavaModelException {
		final HashMap<String, Map<String, Integer[]>> list_maps = new HashMap<String, Map<String, Integer[]>>();
		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {

			mapVariaveis = new HashMap<String, Integer[]>();
			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					return addVariableToMap(node, listaImplementacoesList);

				}

				@Override
				public boolean visit(IfStatement node) {
					nomeVariavelContains = "";
					argumentoIfContains = "";
					node.getExpression().accept(new ASTVisitor() {
						@Override
						public boolean visit(MethodInvocation no) {
							if (no.getExpression() == null)
								return true;
							String variavel = getVariableExpressionName(no);
							if (mapVariaveis.containsKey(variavel)) {
								String metodo = no.getName()
										.getFullyQualifiedName();
								if (metodo.equals("contains")) {
									nomeVariavelContains = variavel;
									argumentoIfContains = no.arguments().get(0)
											.toString();
								}
							}
							return true;
						}
					});
					node.getThenStatement().accept(new ASTVisitor() {
						@Override
						public boolean visit(MethodInvocation node) {
							if (node.getExpression() == null)
								return true;
							String variavel = getVariableExpressionName(node);
							if (mapVariaveis.containsKey(variavel)) {
								String metodo = node.getName()
										.getFullyQualifiedName();
								if (metodo.equals("add"))
									if (nomeVariavelContains.equals(variavel)
											&& argumentoIfContains.equals(node
													.arguments().get(0)
													.toString()))
										mapVariaveis.get(variavel)[0]++;
							}
							return true;
						}
					});

					return true;
				}

				@Override
				public boolean visit(MethodInvocation node) {
					if (node.getExpression() == null)
						return true;
					String variavel = getVariableExpressionName(node);
					if (mapVariaveis.containsKey(variavel)) {
						String metodo = node.getName().getFullyQualifiedName();
						if (metodo.equals("add"))
							mapVariaveis.get(variavel)[1]++;
						if (listaMetodosUsamOrdem.contains(metodo))
							mapVariaveis.get(variavel)[2]++;
					}
					return true;
				}
			});
			list_maps.put(unit.getElementName(), mapVariaveis);
		}
		return list_maps;
	}

	private String getVariableExpressionName(MethodInvocation node) {
		String variavel = node.getExpression().toString();
		if (variavel.contains("this.")) {
			String[] var = variavel.split(java.util.regex.Pattern.quote("."));
			variavel = var[1];
		}
		return variavel;
	}

	private boolean addVariableToMap(ClassInstanceCreation node,
			List<String> listaImplementacoes) {
		String[] variavel_e_tipo = checaClasseInstancia(node);
		if (variavel_e_tipo[1] == null)
			return false;
		if (listaImplementacoes.contains(variavel_e_tipo[1])) {
			if (!mapVariaveis.containsKey(variavel_e_tipo[0])) {
				Integer[] resul = { 0, 0, 0 };
				mapVariaveis.put(variavel_e_tipo[0], resul);
			}
		}
		return true;
	}

	// public HashMap<String, Map<String, Integer[]>> containsAntesDeAddSet(
	// IPackageFragment mypackage) throws JavaModelException {
	// final HashMap<String, Map<String, Integer[]>> list_maps = new
	// HashMap<String, Map<String, Integer[]>>();
	// for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
	//
	// mapVariaveis = new HashMap<String, Integer[]>();
	// ASTNode parsed_node = parse(unit);
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// return addVariableToMap(node, listaImplementacoesSet);
	// }
	//
	// public boolean visit(IfStatement node) {
	// nomeVariavelContains = "";
	// node.getExpression().accept(new ASTVisitor() {
	// @Override
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (mapVariaveis.containsKey(variavel)) {
	// String metodo = node.getName()
	// .getFullyQualifiedName();
	// if (metodo.equals("contains"))
	// nomeVariavelContains = variavel;
	// }
	// return true;
	// }
	// });
	// node.getThenStatement().accept(new ASTVisitor() {
	// @Override
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (mapVariaveis.containsKey(variavel)) {
	// String metodo = node.getName()
	// .getFullyQualifiedName();
	// if (metodo.equals("add"))
	// if (nomeVariavelContains.equals(variavel))
	// mapVariaveis.get(variavel)[0]++;
	// }
	// return true;
	// }
	// });
	//
	// return true;
	// }
	//
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (mapVariaveis.containsKey(variavel)) {
	// String metodo = node.getName().getFullyQualifiedName();
	// if (metodo.equals("add"))
	// mapVariaveis.get(variavel)[1]++;
	// }
	// return true;
	// }
	// });
	// list_maps.put(unit.getElementName(), mapVariaveis);
	// }
	// return list_maps;
	// }

	public HashMap<String, Map<String, Integer>> variaveisChamadasToArraySet(
			IPackageFragment mypackage) throws JavaModelException {
		final HashMap<String, Map<String, Integer>> list_maps = new HashMap<String, Map<String, Integer>>();

		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
			mapVariaveisSet = new HashMap<String, Integer>();
			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					String[] variavel_e_tipo = checaClasseInstancia(node);
					if (variavel_e_tipo[1] == null)
						return false;
					if (listaImplementacoesSet.contains(variavel_e_tipo[1]))
						if (!mapVariaveisSet.containsKey(variavel_e_tipo[0]))
							mapVariaveisSet.put(variavel_e_tipo[0], 0);
					return true;
				}

				@Override
				public boolean visit(MethodInvocation node) {
					if (node.getExpression() == null)
						return true;
					String variavel = getVariableExpressionName(node);
					if (mapVariaveisSet.containsKey(variavel)) {
						String metodo = node.getName().getFullyQualifiedName();
						if (metodo.equals("toArray")) {
							Integer valor = mapVariaveisSet.get(variavel);
							valor++;
							mapVariaveisSet.put(variavel, valor);
						}
					}
					return true;
				}

			});
			list_maps.put(unit.getElementName(), mapVariaveisSet);
		}
		return list_maps;
	}

	public HashMap<String, Map<String, Integer[]>> variaveisChamadasValuesEKeySetMap(
			IPackageFragment mypackage) throws JavaModelException {
		final HashMap<String, Map<String, Integer[]>> list_maps = new HashMap<String, Map<String, Integer[]>>();
		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
			mapVariaveis = new HashMap<String, Integer[]>();
			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					String[] variavel_e_tipo = checaClasseInstancia(node);
					if (variavel_e_tipo[1] == null)
						return false;
					if (listaImplementacoesMap.contains(variavel_e_tipo[1])) {
						if (!mapVariaveis.containsKey(variavel_e_tipo[0])) {
							Integer[] resultado = { 0, 0 };
							mapVariaveis.put(variavel_e_tipo[0], resultado);
						}
					}
					return true;
				}

				@Override
				public boolean visit(MethodInvocation node) {
					if (node.getExpression() == null)
						return true;
					String variavel = getVariableExpressionName(node);
					if (mapVariaveis.containsKey(variavel)) {
						String metodo = node.getName().getFullyQualifiedName();
						if (metodo.equals("values")) {
							mapVariaveis.get(variavel)[0]++;
						} else if (metodo.equals("keySet")) {
							mapVariaveis.get(variavel)[1]++;
						}
					}
					return true;
				}
			});
			list_maps.put(unit.getElementName(), mapVariaveis);
		}
		return list_maps;
	}

	public Map<String, HashSet<String>> variaveisDeClasse(
			IPackageFragment mypackage, final String classe)
			throws JavaModelException {
		final Map<String, HashSet<String>> result = new HashMap<String, HashSet<String>>();
		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
			variaveisTemporarias = new HashSet<String>();
			// nome_variaveis = new HashSet<String>();
			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					String[] variavel_e_tipo = checaClasseInstancia(node);
					// nome_variaveis.add(variavel_e_tipo[0]);

					if (classe.equals(variavel_e_tipo[1])) {
						String variavel = variavel_e_tipo[0];
						variaveisTemporarias.add(variavel);
					}
					return true;
				}
			});
			result.put(unit.getElementName(), variaveisTemporarias);
		}
		return result;
	}

	public HashMap<String, Map<String, Integer[]>> variaveisMetodosGetAddRemove(
			IPackageFragment mypackage, final String classe)
			throws JavaModelException {
		final HashMap<String, Map<String, Integer[]>> list_maps = new HashMap<String, Map<String, Integer[]>>();
		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
			mapVariaveis = new HashMap<String, Integer[]>();
			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					String[] variavel_e_tipo = checaClasseInstancia(node);
					if (variavel_e_tipo[1] == null)
						return false;
					if (variavel_e_tipo[1].equals(classe)) {
						if (!mapVariaveis.containsKey(variavel_e_tipo[0])) {
							Integer[] resultado = { 0, 0, 0 };
							mapVariaveis.put(variavel_e_tipo[0], resultado);
						}
					}
					return true;
				}

				@Override
				public boolean visit(MethodInvocation node) {
					if (node.getExpression() == null)
						return true;
					String variavel = getVariableExpressionName(node);
					if (mapVariaveis.containsKey(variavel)) {
						String metodo = node.getName().getFullyQualifiedName();
						if (metodo.equals("get") || metodo.equals("contains")
								|| metodo.equals("containsAll")
								|| metodo.equals("indexOf")
								|| metodo.equals("size")
								|| metodo.equals("element")
								|| metodo.equals("getFirst")
								|| metodo.equals("getLast")
								|| metodo.equals("lastIndexOf")
								|| metodo.equals("peek")
								|| metodo.equals("peekFirst")
								|| metodo.equals("peekLast")) {
							mapVariaveis.get(variavel)[0]++;
						} else if (metodo.equals("add")
								|| metodo.equals("addAll")
								|| metodo.equals("set")
								|| metodo.equals("remove")
								|| metodo.equals("removeAll")
								|| metodo.equals("removeRange")
								|| metodo.equals("addFirst")
								|| metodo.equals("addLast")
								|| metodo.equals("offer")
								|| metodo.equals("offerFirst")
								|| metodo.equals("offerLast")
								|| metodo.equals("poll")
								|| metodo.equals("pollFirst")
								|| metodo.equals("pollLast")
								|| metodo.equals("pop")
								|| metodo.equals("push")
								|| metodo.equals("removeFirst")
								|| metodo.equals("removeFirstOccurrence")
								|| metodo.equals("removeLastOccurrence")
								|| metodo.equals("removeLast")) {
							mapVariaveis.get(variavel)[1]++;
						}
					}
					return true;
				}
			});
			list_maps.put(unit.getElementName(), mapVariaveis);
		}
		return list_maps;
	}

	// public HashMap<String, Map<String, Integer[]>> variaveisMetodosNaoPilha(
	// IPackageFragment mypackage) throws JavaModelException {
	// final HashMap<String, Map<String, Integer[]>> list_maps = new
	// HashMap<String, Map<String, Integer[]>>();
	// for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
	// mapVariaveis = new HashMap<String, Integer[]>();
	// ASTNode parsed_node = parse(unit);
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// String[] variavel_e_tipo = checaClasseInstancia(node);
	// if (variavel_e_tipo[1] == null)
	// return false;
	// if (variavel_e_tipo[1].equals("Stack")) {
	// if (!mapVariaveis.containsKey(variavel_e_tipo[0])) {
	// Integer[] resultado = { 0, 0, 0 };
	// mapVariaveis.put(variavel_e_tipo[0], resultado);
	// }
	// }
	// return true;
	// }
	//
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (mapVariaveis.containsKey(variavel)) {
	// String metodo = node.getName().getFullyQualifiedName();
	// if (metodo.equals("add")) {
	// mapVariaveis.get(variavel)[0]++;
	// } else if (metodo.equals("remove")) {
	// mapVariaveis.get(variavel)[1]++;
	// } else if (metodo.equals("set")) {
	// mapVariaveis.get(variavel)[2]++;
	// }
	// }
	// return true;
	// }
	// });
	// list_maps.put(unit.getElementName(), mapVariaveis);
	// }
	// return list_maps;
	// }
	//
	// public Integer contaUtilizacaoDeDequeLinkedListComoList(
	// IPackageFragment mypackage) throws JavaModelException {
	// result = 0;
	// for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
	// nome_variaveis = new HashSet<String>();
	// ASTNode parsed_node = parse(unit);
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// String[] variavel_e_tipo = checaClasseInstancia(node);
	// if (variavel_e_tipo[1] == null)
	// return false;
	// if (variavel_e_tipo[1].equals("LinkedList")) {
	// nome_variaveis.add(variavel_e_tipo[0]);
	// }
	// return true;
	// }
	//
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (nome_variaveis.contains(variavel)) {
	// if (checkVariavelDeclaringClass(node, "java.util.Deque")) {
	// String metodo = node.getName()
	// .getFullyQualifiedName();
	// if (metodo.equals("add") || metodo.equals("remove")
	// || metodo.equals("get"))
	// result++;
	// nome_variaveis.remove(variavel);
	// }
	// }
	// return true;
	// }
	// });
	// }
	// return result;
	// }

	// public Integer[] contaMetodosDeTreemap(IPackageFragment mypackage)
	// throws JavaModelException {
	// final Integer[] resultado = { 0, 0, 0, 0, 0 };
	// for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
	// nome_variaveis = new HashSet<String>();
	// ASTNode parsed_node = parse(unit);
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// String[] variavel_e_tipo = checaClasseInstancia(node);
	// if (variavel_e_tipo[1] == null)
	// return false;
	// if (variavel_e_tipo[1].equals("TreeMap")) {
	// nome_variaveis.add(variavel_e_tipo[0]);
	// }
	// return true;
	// }
	//
	// public boolean visit(MethodInvocation node) {
	// if (node.getExpression() == null)
	// return true;
	// String variavel = getVariableExpressionName(node);
	// if (nome_variaveis.contains(variavel)) {
	// String metodo = node.getName().getFullyQualifiedName();
	// if (metodo.equals("descendingKeySet")) {
	// resultado[0]++;
	// } else if (metodo.equals("firstEntry")) {
	// resultado[1]++;
	// } else if (metodo.equals("firstKey")) {
	// resultado[2]++;
	// } else if (metodo.equals("lastEntry")) {
	// resultado[3]++;
	// } else if (metodo.equals("subMap")) {
	// resultado[4]++;
	// }
	//
	// }
	// return true;
	// }
	// });
	// }
	// return resultado;
	// }

	// public Integer[] contaComparatorTreeMap(IPackageFragment mypackage)
	// throws JavaModelException {
	// final Integer[] resultado = { 0, 0 };
	// for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
	// nome_variaveis = new HashSet<String>();
	// ASTNode parsed_node = parse(unit);
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// String[] variavel_e_tipo = checaClasseInstancia(node);
	// if (variavel_e_tipo[1] == null)
	// return false;
	// if (variavel_e_tipo[1].equals("Comparator")) {
	// nome_variaveis.add(variavel_e_tipo[0]);
	// }
	// return true;
	// }
	// });
	//
	// parsed_node.accept(new ASTVisitor() {
	// public boolean visit(ClassInstanceCreation node) {
	// String[] variavel_e_tipo = checaClasseInstancia(node);
	// if (variavel_e_tipo[1] == null)
	// return false;
	// if (variavel_e_tipo[1].equals("TreeMap")) {
	// if (node.arguments().isEmpty())
	// resultado[1]++;
	// else {
	// if (nome_variaveis.contains(node.arguments().get(0)
	// .toString()))
	// resultado[0]++;
	// }
	// }
	// return true;
	// }
	// });
	// }
	// return resultado;
	//
	// }

	public HashMap<String, Map<String, Integer[]>> variaveisMetodosSynchronizedVector(
			IPackageFragment mypackage) throws JavaModelException {
		final HashMap<String, Map<String, Integer[]>> synchronized_map = new HashMap<String, Map<String, Integer[]>>();

		for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
			mapVariaveis = new HashMap<String, Integer[]>();
			lista_posicao_chamadas_metodos_vector_synchronized = new ArrayList<Integer>();

			ASTNode parsed_node = parse(unit);
			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(ClassInstanceCreation node) {
					String[] variavel_e_tipo = checaClasseInstancia(node);
					if (variavel_e_tipo[1] == null)
						return false;
					if (variavel_e_tipo[1].equals("Vector")) {
						Integer[] resul = { 0, 0 };
						mapVariaveis.put(variavel_e_tipo[0], resul);
					}
					return true;
				}
			});

			parsed_node.accept(new ASTVisitor() {
				@Override
				public boolean visit(SynchronizedStatement node) {
					node.accept(new ASTVisitor() {
						@Override
						public boolean visit(MethodInvocation node) {
							if (node.getExpression() == null)
								return true;
							String variavel = getVariableExpressionName(node);
							if (mapVariaveis.containsKey(variavel)) {
								if (!lista_posicao_chamadas_metodos_vector_synchronized
										.contains(node.getStartPosition()))
									lista_posicao_chamadas_metodos_vector_synchronized
											.add(node.getStartPosition());
							}
							return true;
						}
					});
					return true;
				}
			});

			parsed_node.accept(new ASTVisitor() {

				@Override
				public boolean visit(MethodInvocation node) {
					if (node.getExpression() == null)
						return true;
					String variavel = getVariableExpressionName(node);
					if (mapVariaveis.containsKey(variavel)) {
						if (lista_posicao_chamadas_metodos_vector_synchronized
								.contains(node.getStartPosition())) {
							mapVariaveis.get(variavel)[0]++;
						} else if (!lista_posicao_chamadas_metodos_vector_synchronized
								.contains(node.getStartPosition())) {
							mapVariaveis.get(variavel)[1]++;
						}
					}
					return true;
				}
			});
			synchronized_map.put(unit.getElementName(), mapVariaveis);
		}
		return synchronized_map;

	}

	private String[] checaClasseInstancia(ClassInstanceCreation node) {
		String[] resultado = new String[2];
		Expression e = null;
		if (node.getParent() instanceof Assignment) {
			e = ((Assignment) node.getParent()).getLeftHandSide();
		} else if (node.getParent() instanceof VariableDeclarationFragment) {
			e = ((VariableDeclarationFragment) node.getParent()).getName();
		}
		if (e != null) {
			String variavel = e.toString();

			if (variavel.contains("this.")) {
				String[] var_array = variavel.split(java.util.regex.Pattern
						.quote("."));
				variavel = var_array[1];
			}
			String tipo = node.getType().toString();
			String[] tipo_array = tipo
					.split(java.util.regex.Pattern.quote("<"));
			resultado[0] = variavel;
			resultado[1] = tipo_array[0];
		}
		return resultado;
	}

	// public boolean checkVariavelDeclaringClass(MethodInvocation node,
	// String classe) {
	// boolean resp = false;
	// Expression expressao = node.getExpression();
	// if (expressao == null) {
	// return resp;
	// }
	// ITypeBinding binding = expressao.resolveTypeBinding();
	// if (binding == null) {
	// return resp;
	// }
	// String object = "java.util.Object";
	// if (binding == null || object.equals(binding.getBinaryName())) {
	// resp = false;
	// }
	// if (classe.equals(binding.getBinaryName())) {
	// resp = true;
	// }
	// binding = binding.getSuperclass();
	// return resp;
	//
	// }

	// public boolean checkMetodoVariableDeclaringClass(MethodInvocation node,
	// List<String> classe, String metodo) {
	// boolean resp = false;
	// Expression expressao = node.getExpression();
	// if (expressao == null) {
	// return resp;
	// }
	// ITypeBinding binding = expressao.resolveTypeBinding();
	// if (binding == null) {
	// return resp;
	// }
	// String object = "java.util.Object";
	// if (binding == null || object.equals(binding.getBinaryName())) {
	// resp = false;
	// }
	// if (classe.contains(binding.getBinaryName())) {
	// if (metodo.equals(node.getName().getFullyQualifiedName()))
	// resp = true;
	// }
	// return resp;
	//
	// }

	private void povoaListaMetodosUsamOrdem() {
		listaMetodosUsamOrdem.add("get");
		listaMetodosUsamOrdem.add("indexOf");
		listaMetodosUsamOrdem.add("lastIndexOf");
		listaMetodosUsamOrdem.add("set");
		listaMetodosUsamOrdem.add("subList");
	}

	private static ASTNode parse(ICompilationUnit unit) {
		ASTParser parser = ASTParser.newParser(AST.JLS4);
		parser.setKind(ASTParser.K_COMPILATION_UNIT);
		parser.setSource(unit);
		parser.setResolveBindings(true);
		return parser.createAST(null); // parse
	}
}